package com.airy.highSpeed.controller;

import com.airy.highSpeed.entity.StationparentEntity;
import com.airy.highSpeed.service.StationparentService;
import com.airy.highSpeed.utils.PageUtils;
import com.airy.highSpeed.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * @Author: Ding Ya Kun.
 * @Description:
 * @Date:Created in 2020.12.22 13:29
 */
@RestController
@RequestMapping("product/stationparent")
public class StationparentController {
    @Autowired
    private StationparentService stationparentService;

    /**
     * 查询天津所有收费站
     */
    @RequestMapping("/findAll")
    public List<StationparentEntity> findAll() {
        List<StationparentEntity> stationparentEntityList = stationparentService.findAll();

        return stationparentEntityList;
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = stationparentService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id) {
        StationparentEntity stationparentEntity = stationparentService.getById(id);

        return R.ok().put("stationparentEntity", stationparentEntity);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody StationparentEntity stationparentEntity) {
        stationparentService.save(stationparentEntity);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody StationparentEntity stationparentEntity) {
        stationparentService.updateById(stationparentEntity);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids) {
        stationparentService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
